package com.blb.zy_community.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blb.zy_community.entity.ResponseResult;
import com.blb.zy_community.entity.SysOperLog;
import com.blb.zy_community.service.ISysOperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 操作日志记录 前端控制器
 * </p>
 *
 * @author 二组
 * @since 2023-06-18
 */
@CrossOrigin
@RestController
public class SysOperLogController {
    @Autowired
    private ISysOperLogService sysOperLogService;

    /**
     * 获取分页数据
     * @param current   当前页数
     * @param size      每页几行
     * @param title     系统模块  模块标题
     * @param operName  操作人员
     * @param requestMethod    类型      方法名称
     * @param status    状态      操作状态
     * @param operTimeStart     操作时间范围_开始
     * @param operTimeEnd       操作时间范围_结束
     * @return
     */
    @GetMapping("/sysOperLogPage/page")
    public ResponseResult<SysOperLog> getSysOperLogPage(
            @RequestParam(required = false,defaultValue = "1") Long current,
            @RequestParam(required = false,defaultValue = "5") Long size,
            @RequestParam(required = false) String title,
            @RequestParam(required = false) String operName,
            @RequestParam(required = false) String requestMethod,
            @RequestParam(required = false) String status,
            @RequestParam(required = false) String operTimeStart,
            @RequestParam(required = false) String operTimeEnd
    ){
        Page<SysOperLog>  sysOperLogPage= sysOperLogService.getSysOperLogPage(new Page<>(current,size),
                title,operName,requestMethod,status,operTimeStart,operTimeEnd);
        return ResponseResult.ok(sysOperLogPage);
    }

    /**
     * 操作日志批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/sysOperLogPage/batchDelete/{ids}")
    public ResponseResult<Long[]> batchDeleteBySysOperLogIds(@PathVariable("ids") String[] ids) {
        List<String> list = Arrays.asList(ids);
        sysOperLogService.removeBatchByIds(list);
        return ResponseResult.ok(ids);
    }



}
